package com.flurry.sdk;

import com.flurry.sdk.ll;
import com.google.android.gms.ads.identifier.AdvertisingIdClient;
import java.io.Closeable;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class jl {
    private static final String b = jl.class.getSimpleName();
    private static jl c;
    public final Map<jt, byte[]> a = new HashMap();
    private final Set<String> d;
    private final kh<ll> e = new kh<ll>() {
        public final /* synthetic */ void a(kg kgVar) {
            switch (AnonymousClass4.a[((ll) kgVar).c - 1]) {
                case 1:
                    if (jl.this.b()) {
                        jy.a().b(new ma() {
                            public final void a() {
                                jl.this.d();
                            }
                        });
                        return;
                    }
                    return;
                default:
                    return;
            }
        }
    };
    private a f = a.NONE;
    private jv g;
    private String h;

    enum a {
        NONE,
        ADVERTISING,
        DEVICE,
        REPORTED_IDS,
        FINISHED
    }

    public static synchronized jl a() {
        jl jlVar;
        synchronized (jl.class) {
            if (c == null) {
                c = new jl();
            }
            jlVar = c;
        }
        return jlVar;
    }

    private jl() {
        HashSet hashSet = new HashSet();
        hashSet.add("null");
        hashSet.add("9774d56d682e549c");
        hashSet.add("dead00beef");
        this.d = Collections.unmodifiableSet(hashSet);
        ki.a().a("com.flurry.android.sdk.FlurrySessionEvent", this.e);
        jy.a().b(new ma() {
            public final void a() {
                jl.b(jl.this);
            }
        });
    }

    public final boolean b() {
        return a.FINISHED.equals(this.f);
    }

    public final boolean c() {
        if (this.g != null && this.g.b) {
            return false;
        }
        return true;
    }

    /* renamed from: com.flurry.sdk.jl$4  reason: invalid class name */
    static /* synthetic */ class AnonymousClass4 {
        static final /* synthetic */ int[] a = new int[ll.a.a().length];

        static {
            b = new int[a.values().length];
            try {
                b[a.NONE.ordinal()] = 1;
            } catch (NoSuchFieldError e) {
            }
            try {
                b[a.ADVERTISING.ordinal()] = 2;
            } catch (NoSuchFieldError e2) {
            }
            try {
                b[a.DEVICE.ordinal()] = 3;
            } catch (NoSuchFieldError e3) {
            }
            try {
                b[a.REPORTED_IDS.ordinal()] = 4;
            } catch (NoSuchFieldError e4) {
            }
            try {
                a[ll.a.a - 1] = 1;
            } catch (NoSuchFieldError e5) {
            }
        }
    }

    /* access modifiers changed from: private */
    public void d() {
        ly.b();
        this.g = e();
        if (b()) {
            h();
            ki.a().a((kg) new jn());
        }
    }

    private static jv e() {
        try {
            AdvertisingIdClient.Info advertisingIdInfo = AdvertisingIdClient.getAdvertisingIdInfo(jy.a().a);
            return new jv(advertisingIdInfo.getId(), advertisingIdInfo.isLimitAdTrackingEnabled());
        } catch (NoClassDefFoundError e2) {
            km.b(b, "There is a problem with the Google Play Services library, which is required for Android Advertising ID support. The Google Play Services library should be integrated in any app shipping in the Play Store that uses analytics or advertising.");
            return null;
        } catch (Exception e3) {
            km.b(b, "GOOGLE PLAY SERVICES ERROR: " + e3.getMessage());
            km.b(b, "There is a problem with the Google Play Services library, which is required for Android Advertising ID support. The Google Play Services library should be integrated in any app shipping in the Play Store that uses analytics or advertising.");
            return null;
        }
    }

    private static void a(String str, File file) {
        DataOutputStream dataOutputStream;
        try {
            dataOutputStream = new DataOutputStream(new FileOutputStream(file));
            try {
                dataOutputStream.writeInt(1);
                dataOutputStream.writeUTF(str);
                ly.a((Closeable) dataOutputStream);
            } catch (Throwable th) {
                th = th;
                try {
                    km.a(6, b, "Error when saving deviceId", th);
                    ly.a((Closeable) dataOutputStream);
                } catch (Throwable th2) {
                    th = th2;
                    ly.a((Closeable) dataOutputStream);
                    throw th;
                }
            }
        } catch (Throwable th3) {
            th = th3;
            dataOutputStream = null;
            ly.a((Closeable) dataOutputStream);
            throw th;
        }
    }

    private static String f() {
        DataInputStream dataInputStream;
        Throwable th;
        String str = null;
        File fileStreamPath = jy.a().a.getFileStreamPath(".flurryb.");
        if (fileStreamPath != null && fileStreamPath.exists()) {
            try {
                dataInputStream = new DataInputStream(new FileInputStream(fileStreamPath));
                try {
                    if (1 == dataInputStream.readInt()) {
                        str = dataInputStream.readUTF();
                    }
                    ly.a((Closeable) dataInputStream);
                } catch (Throwable th2) {
                    th = th2;
                }
            } catch (Throwable th3) {
                dataInputStream = null;
                th = th3;
                ly.a((Closeable) dataInputStream);
                throw th;
            }
        }
        return str;
    }

    private String g() {
        String[] list;
        File fileStreamPath;
        DataInputStream dataInputStream;
        Throwable th;
        String str = null;
        File filesDir = jy.a().a.getFilesDir();
        if (!(filesDir == null || (list = filesDir.list(new FilenameFilter() {
            public final boolean accept(File file, String str) {
                return str.startsWith(".flurryagent.");
            }
        })) == null || list.length == 0 || (fileStreamPath = jy.a().a.getFileStreamPath(list[0])) == null || !fileStreamPath.exists())) {
            try {
                dataInputStream = new DataInputStream(new FileInputStream(fileStreamPath));
                try {
                    if (46586 == dataInputStream.readUnsignedShort()) {
                        if (2 == dataInputStream.readUnsignedShort()) {
                            dataInputStream.readUTF();
                            str = dataInputStream.readUTF();
                        }
                    }
                    ly.a((Closeable) dataInputStream);
                } catch (Throwable th2) {
                    th = th2;
                }
            } catch (Throwable th3) {
                dataInputStream = null;
                th = th3;
                ly.a((Closeable) dataInputStream);
                throw th;
            }
        }
        return str;
    }

    private void h() {
        String str;
        if (this.g == null) {
            str = null;
        } else {
            str = this.g.a;
        }
        if (str != null) {
            km.a(3, b, "Fetched advertising id");
            this.a.put(jt.AndroidAdvertisingId, ly.e(str));
        }
        String str2 = this.h;
        if (str2 != null) {
            km.a(3, b, "Fetched device id");
            this.a.put(jt.DeviceId, ly.e(str2));
        }
    }

    /* JADX WARNING: Can't fix incorrect switch cases order */
    /* JADX WARNING: Removed duplicated region for block: B:23:0x008c A[Catch:{ Exception -> 0x002b }] */
    /* JADX WARNING: Removed duplicated region for block: B:28:0x0099 A[Catch:{ Exception -> 0x002b }] */
    /* JADX WARNING: Removed duplicated region for block: B:29:0x00a9 A[Catch:{ Exception -> 0x002b }] */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    static /* synthetic */ void b(jl r8) {
        /*
            r6 = 37
        L_0x0002:
            com.flurry.sdk.jl$a r0 = com.flurry.sdk.jl.a.FINISHED
            com.flurry.sdk.jl$a r1 = r8.f
            boolean r0 = r0.equals(r1)
            if (r0 != 0) goto L_0x0111
            int[] r0 = com.flurry.sdk.jl.AnonymousClass4.b
            com.flurry.sdk.jl$a r1 = r8.f
            int r1 = r1.ordinal()
            r0 = r0[r1]
            switch(r0) {
                case 1: goto L_0x004e;
                case 2: goto L_0x0053;
                case 3: goto L_0x0058;
                case 4: goto L_0x005d;
                default: goto L_0x0019;
            }
        L_0x0019:
            int[] r0 = com.flurry.sdk.jl.AnonymousClass4.b     // Catch:{ Exception -> 0x002b }
            com.flurry.sdk.jl$a r1 = r8.f     // Catch:{ Exception -> 0x002b }
            int r1 = r1.ordinal()     // Catch:{ Exception -> 0x002b }
            r0 = r0[r1]     // Catch:{ Exception -> 0x002b }
            switch(r0) {
                case 2: goto L_0x0027;
                case 3: goto L_0x0062;
                case 4: goto L_0x010c;
                default: goto L_0x0026;
            }     // Catch:{ Exception -> 0x002b }
        L_0x0026:
            goto L_0x0002
        L_0x0027:
            r8.d()     // Catch:{ Exception -> 0x002b }
            goto L_0x0002
        L_0x002b:
            r0 = move-exception
            r1 = 4
            java.lang.String r2 = b
            java.lang.StringBuilder r3 = new java.lang.StringBuilder
            java.lang.String r4 = "Exception during id fetch:"
            r3.<init>(r4)
            com.flurry.sdk.jl$a r4 = r8.f
            java.lang.StringBuilder r3 = r3.append(r4)
            java.lang.String r4 = ", "
            java.lang.StringBuilder r3 = r3.append(r4)
            java.lang.StringBuilder r0 = r3.append(r0)
            java.lang.String r0 = r0.toString()
            com.flurry.sdk.km.a((int) r1, (java.lang.String) r2, (java.lang.String) r0)
            goto L_0x0002
        L_0x004e:
            com.flurry.sdk.jl$a r0 = com.flurry.sdk.jl.a.ADVERTISING
            r8.f = r0
            goto L_0x0019
        L_0x0053:
            com.flurry.sdk.jl$a r0 = com.flurry.sdk.jl.a.DEVICE
            r8.f = r0
            goto L_0x0019
        L_0x0058:
            com.flurry.sdk.jl$a r0 = com.flurry.sdk.jl.a.REPORTED_IDS
            r8.f = r0
            goto L_0x0019
        L_0x005d:
            com.flurry.sdk.jl$a r0 = com.flurry.sdk.jl.a.FINISHED
            r8.f = r0
            goto L_0x0019
        L_0x0062:
            com.flurry.sdk.ly.b()     // Catch:{ Exception -> 0x002b }
            com.flurry.sdk.jy r0 = com.flurry.sdk.jy.a()     // Catch:{ Exception -> 0x002b }
            android.content.Context r0 = r0.a     // Catch:{ Exception -> 0x002b }
            android.content.ContentResolver r0 = r0.getContentResolver()     // Catch:{ Exception -> 0x002b }
            java.lang.String r1 = "android_id"
            java.lang.String r1 = android.provider.Settings.Secure.getString(r0, r1)     // Catch:{ Exception -> 0x002b }
            boolean r0 = android.text.TextUtils.isEmpty(r1)     // Catch:{ Exception -> 0x002b }
            if (r0 != 0) goto L_0x0097
            java.util.Locale r0 = java.util.Locale.US     // Catch:{ Exception -> 0x002b }
            java.lang.String r0 = r1.toLowerCase(r0)     // Catch:{ Exception -> 0x002b }
            java.util.Set<java.lang.String> r2 = r8.d     // Catch:{ Exception -> 0x002b }
            boolean r0 = r2.contains(r0)     // Catch:{ Exception -> 0x002b }
            if (r0 != 0) goto L_0x0097
            r0 = 1
        L_0x008a:
            if (r0 != 0) goto L_0x0099
            r0 = 0
        L_0x008d:
            boolean r1 = android.text.TextUtils.isEmpty(r0)     // Catch:{ Exception -> 0x002b }
            if (r1 != 0) goto L_0x00a9
        L_0x0093:
            r8.h = r0     // Catch:{ Exception -> 0x002b }
            goto L_0x0002
        L_0x0097:
            r0 = 0
            goto L_0x008a
        L_0x0099:
            java.lang.StringBuilder r0 = new java.lang.StringBuilder     // Catch:{ Exception -> 0x002b }
            java.lang.String r2 = "AND"
            r0.<init>(r2)     // Catch:{ Exception -> 0x002b }
            java.lang.StringBuilder r0 = r0.append(r1)     // Catch:{ Exception -> 0x002b }
            java.lang.String r0 = r0.toString()     // Catch:{ Exception -> 0x002b }
            goto L_0x008d
        L_0x00a9:
            java.lang.String r0 = f()     // Catch:{ Exception -> 0x002b }
            boolean r1 = android.text.TextUtils.isEmpty(r0)     // Catch:{ Exception -> 0x002b }
            if (r1 == 0) goto L_0x0093
            java.lang.String r0 = r8.g()     // Catch:{ Exception -> 0x002b }
            boolean r1 = android.text.TextUtils.isEmpty(r0)     // Catch:{ Exception -> 0x002b }
            if (r1 == 0) goto L_0x00f0
            double r0 = java.lang.Math.random()     // Catch:{ Exception -> 0x002b }
            long r0 = java.lang.Double.doubleToLongBits(r0)     // Catch:{ Exception -> 0x002b }
            long r2 = java.lang.System.nanoTime()     // Catch:{ Exception -> 0x002b }
            com.flurry.sdk.jy r4 = com.flurry.sdk.jy.a()     // Catch:{ Exception -> 0x002b }
            android.content.Context r4 = r4.a     // Catch:{ Exception -> 0x002b }
            java.lang.String r4 = com.flurry.sdk.lv.a(r4)     // Catch:{ Exception -> 0x002b }
            long r4 = com.flurry.sdk.ly.i(r4)     // Catch:{ Exception -> 0x002b }
            long r4 = r4 * r6
            long r2 = r2 + r4
            long r2 = r2 * r6
            long r0 = r0 + r2
            java.lang.StringBuilder r2 = new java.lang.StringBuilder     // Catch:{ Exception -> 0x002b }
            java.lang.String r3 = "ID"
            r2.<init>(r3)     // Catch:{ Exception -> 0x002b }
            r3 = 16
            java.lang.String r0 = java.lang.Long.toString(r0, r3)     // Catch:{ Exception -> 0x002b }
            java.lang.StringBuilder r0 = r2.append(r0)     // Catch:{ Exception -> 0x002b }
            java.lang.String r0 = r0.toString()     // Catch:{ Exception -> 0x002b }
        L_0x00f0:
            boolean r1 = android.text.TextUtils.isEmpty(r0)     // Catch:{ Exception -> 0x002b }
            if (r1 != 0) goto L_0x0093
            com.flurry.sdk.jy r1 = com.flurry.sdk.jy.a()     // Catch:{ Exception -> 0x002b }
            android.content.Context r1 = r1.a     // Catch:{ Exception -> 0x002b }
            java.lang.String r2 = ".flurryb."
            java.io.File r1 = r1.getFileStreamPath(r2)     // Catch:{ Exception -> 0x002b }
            boolean r2 = com.flurry.sdk.lx.a(r1)     // Catch:{ Exception -> 0x002b }
            if (r2 == 0) goto L_0x0093
            a(r0, r1)     // Catch:{ Exception -> 0x002b }
            goto L_0x0093
        L_0x010c:
            r8.h()     // Catch:{ Exception -> 0x002b }
            goto L_0x0002
        L_0x0111:
            com.flurry.sdk.jm r0 = new com.flurry.sdk.jm
            r0.<init>()
            com.flurry.sdk.ki r1 = com.flurry.sdk.ki.a()
            r1.a((com.flurry.sdk.kg) r0)
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: com.flurry.sdk.jl.b(com.flurry.sdk.jl):void");
    }
}
